package com.gjs.user.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gjs.common.manager.response.RspBody;
import com.gjs.common.pojo.dto.request.PageQuery;
import com.gjs.common.pojo.dto.response.ListPageRsp;
import com.gjs.common.pojo.dto.user.UserQueryDTO;
import com.gjs.user.pojo.dto.user.UserManagementVO;
import com.gjs.user.pojo.entity.User;
import com.gjs.user.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@Api(tags = "用户管理接口")
@RequestMapping("/management")
@RequiredArgsConstructor
public class ManagementController {

    private final IUserService userService;

    @GetMapping("/list")
    @ApiOperation("列表")
    public RspBody<ListPageRsp<UserManagementVO>> list(UserQueryDTO queryDTO, PageQuery pageQuery){
        IPage<User> iPage = userService.page(pageQuery.buildPage(),userService.buildWrapper(queryDTO));
        return RspBody.success(ListPageRsp.of(iPage, UserManagementVO.class));
    }

    @GetMapping("/detail")
    @ApiOperation("详情")
    public RspBody<UserManagementVO> detail(Long id){
        User user = userService.getById(id);
        Assert.notNull(user,"找不到该用户");
        return RspBody.success(BeanUtil.copyProperties(user, UserManagementVO.class));
    }

    @PostMapping("/add")
    @ApiOperation("添加")
    public RspBody add(){
        return RspBody.success();
    }

    @PostMapping("/update")
    @ApiOperation("更新")
    public RspBody update(){
        return RspBody.success();
    }
}
